package com.doit.demo03;

public class test_stop {
    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10000000; i++) {
                    boolean b = Thread.currentThread().isInterrupted();
                    if(b) break;
                    System.out.println(Thread.currentThread().getName()+" "+i);
                }
            }
        });
        t1.start();
        try {
            Thread.sleep(2000);//睡眠2秒  主进程睡眠两秒
//            t1.stop();//已过时
            t1.interrupt();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
